package godardbaudrin.rsa.decrypt;

import godardbaudrin.rsa.Formulas;

/**
 * 
 * @author Destiny
 *
 */
public class DecryptEngine extends DecryptFormulas{
	Formulas form = new Formulas();
	
	final int p = super.getP();
	final int q = super.getQ();
	final double e = super.getE();
	final double n = super.getN();
	final double PhiN = form.getPhiN(p, q);
	double[] privateKey = new double[2];//The private key which contains d for index 0 and n for index 1
	double d;//What we are looking for

	/**
	 * Please give the public key: composition (e, n)
	 * @param e
	 * @param n
	 */
	public DecryptEngine(double e, double n){
		super(e,n);
	}
	
	//TODO write steps of decryption
	
	/**
	 * @return an array for the private key which contains d for index 0 and n for index 1
	 */
	public double[] getPrivateKey(){
		
		//Now we have p, q, e, n, PhiN enjoy ^^
		d = form.getD(e, PhiN);
		privateKey[0] = d;
		privateKey[1] = n;
		
		//Just for test
		System.out.println("p = "+ p +" q = "+ q +" e = "+ e +" n = "+ n +" PhiN = "+ PhiN);
		System.out.println("d = "+ privateKey[0] +" n = "+ privateKey[1]);
		
		return privateKey;
	}
}
